package com.tuo51.core.domain.org;

import com.matt.commons.model.Domain;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

import javax.persistence.*;
import java.util.Date;

@Data
@Entity
@Table(name = "organization" , uniqueConstraints = {
        @UniqueConstraint(columnNames = {
                "creatorId", "bizOrg"
        })
})
@EqualsAndHashCode(callSuper=true)
@ToString(callSuper=true)
public class Organization extends Domain {

    @Column(columnDefinition="varchar(50) COMMENT '机构名称'")
    private String name;

    @Column(columnDefinition = "varchar(32) COMMENT '创建者id'")
    private String creatorId;

    @Column(columnDefinition = "varchar(32) COMMENT '管理员id'")
    private String adminId;

    @Column(columnDefinition = " bit(1) default 0  COMMENT '机构性质 0:用户默认机构 1:授权机构,可以加子用户那种' ")
    private Boolean bizOrg = false;

    @Column(columnDefinition = "varchar(32) COMMENT '机构类型id'")
    private String typeId;

    @Column(columnDefinition = " varchar(10) default '' COMMENT '机构简写CODE， 用作一些园区数据编号生成' ")
    private String code;

    @Column(columnDefinition = " integer default 1  COMMENT '机构序列号，用作园区数据编号生成' ")
    private Integer sequence = 1;

    @Column(columnDefinition = "bit(1) default 0 COMMENT '是否是测试机构 默认否' ")
    private Boolean test = false;

    //机构地址
    @Column(name = "address", columnDefinition = "varchar(100) COMMENT '街道地址'")
    private String address;

    @Column(name = "pca_code", columnDefinition = "varchar(10) COMMENT '地址码'")
    private String pcaCode;

    @Column(name = "pca_code_desc", columnDefinition = "varchar(100) COMMENT '地址码对应的地址, 省P市C区A'")
    private String pcaCodeDesc;

    @Column(name = "contact_number", columnDefinition = "varchar(15) COMMENT '园区联系方式'")
    private String contactNumber;

    @Column(name = "logo", columnDefinition = "varchar(255) COMMENT '园区logo'")
    private String logo;

    //服务终止时间
    @Column
    private Date expireTime;

    @Column
    private Date totalDuration;

    @Transient
    private Integer vipLevel;

    //可创建的报告数量
    @Column
    private Integer restCount;

    //子账号
    @Column(columnDefinition = " integer default 1  COMMENT '现有子账号数量' ")
    private Integer staffCount = 1;

    @Column(columnDefinition = " integer default 1  COMMENT '子账号数量配额' ")
    private Integer staffQuota = 1;

    //
    @Column(name = "source_appid", columnDefinition = "varchar(32) COMMENT '来源appid'")
    private String sourceAppId;


    public static Organization of(String name, Boolean bizOrg, String typeId){
        Organization org = new Organization();
        org.setName(name);
        org.setBizOrg(bizOrg);

        org.setTypeId(typeId);
        return org;
    }

    public  static Organization of(String staffId){
        Organization org = new Organization();
        org.setBizOrg(false);
        org.setStaffCount(1);
        org.setStaffQuota(1);
        org.setAdminId(staffId);
        org.setCreatorId(staffId);

        return org;
    }
}
